﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using TekaMUD.Engine.IO;
using TekaMUD.Engine.Framework;

namespace TekaMUD.Engine.Blocks
{
	/// <summary>
	/// Player status enumeration
	/// </summary>
	public enum PlayerStatus
	{
		/// <summary>
		/// Player isn't connected right now.
		/// </summary>
		Offline,

		/// <summary>
		/// Player just connected to the engine.
		/// </summary>
		New,

		/// <summary>
		/// Player is completing the registering wizard.
		/// </summary>
		Registering,

		/// <summary>
		/// Player is online and active. This should be the normal state for a connected user.
		/// </summary>
		Active,

		/// <summary>
		/// The player's connection might be disconnected.
		/// </summary>
		Lingering,

		/// <summary>
		/// The player is away from the keyboard. Connection timeout periods should be extended. Inactivity timers should be disabled.
		/// </summary>
		AFK,

		/// <summary>
		/// The player as been administrativelly locked and cannot login.
		/// </summary>
		Locked,

		/// <summary>
		/// The player is about to be deleted and should not be included on the next persistence update.
		/// </summary>
		Deleted,
	}

	[Serializable]
	public class Player : RationalAgent
	{
		/// <summary>
		/// Player GUID, for persistence purposes.
		/// </summary>
		private Guid ID;

		public DateTime LastLogin { get; set; }
		public uint InvalidLoginAttempts { get; set; }
		public uint LoginCount { get; set; }
		public bool AutoLook { get; set; }
		public bool Invisible { get; set; }
		public string RealName { get; set; }
		public byte[] PasswordHash { get; set; }
		public uint Level { get; set; }
		public ulong Experience { get; set; }
		
		
		// fix this, broken.
		private volatile PlayerStatus _status;

		public PlayerStatus Status
		{
			get { return _status; }
			set { _status = value; }
		}

		public Player()
		{
			ID = new Guid();
			Status = PlayerStatus.New;
			LoginCount = 0;
			InvalidLoginAttempts = 0;
			Backpack = new ObjectContainer(Configuration.PLAYER_MAX_BACKPACK_ITEMS);
		}

		public void SetName(string name)
		{
			this.Name = name;
		}

		public void Refresh()
		{
			Logger.LogDebug("Refreshing player " + this.Name);
		}

		/// <summary>
		/// Returns the player's current prompt.
		/// </summary>
		public string PlayerPrompt
		{
			get
			{
				return "Tekamud > ";
			}
		}
	}
}
